layui.use(['form','table','element','laytpl','layer','upload','laydate'], function() {
  var table = layui.table;
  var form = layui.form;
  var laydate = layui.laydate;
  var upload = layui.upload;
  //时间选择器
  laydate.render({
    elem: '#chengli'
    ,type: 'date'
  });
  upload.render({
		elem : '#uploader',
		url : '/ssm/file/uploadImage.do',
		done : function(res) {
			if (res.code == '01') {
				$("#uploader")
						.html(
								"<img src='" + res.body + "' style='width: 100px;height: 130px;'/><p>点击重新上传，或将文件拖拽到此处</p>");
				$("#banner_path").val(res.body);
			} else {
				layer.alert("上传失败");
			}
		}
	});

  	init();
    function init(){
    	function getQueryString(name) { 
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
            var r = window.location.search.substr(1).match(reg); 
            if (r != null) return unescape(r[2]); 
            return null; 
        } 
        var id = getQueryString("id");
        var postData = {
        		id:id
        }
        if(id){
	        $.post('/ssm/job/queryList.do',postData,function(data){
	        	var data = data.body.list[0];
	        	if(data!=null){
	                $("#editForm input[id=id]").val(data.id);
	                $("#editForm input[id=title]").val(data.title);
	                $("#editForm input[id=compaign_name]").val(data.compaign_name);
	                $("#editForm input[id=salary]").val(data.salary);
	                $("#editForm input[id=address]").val(data.address);
	                $("#editForm input[id=work_year]").val(data.work_year);
	                $("#editForm input[id=xueli]").val(data.xueli);
	                $("#editForm input[id=renshu]").val(data.renshu);
	                $("#editForm input[id=cellphone]").val(data.cellphone);
	                $("#editForm textarea[id=zhiwei]").val(data.zhiwei);
	                $("#editForm input[id=consumer_id]").val(data.consumer_id);
	   
	        	}
	            form.render('select');
	        })
        }
    }

    	//表单提交事件
    layui.form.on('submit(btnSubmit)', function(data){
    		var postData = {
    				id : $("#id").val(),
    				title : $("#title").val(),
    				compaign_name : $("#compaign_name").val(),
    				salary : $("#salary").val(),
    				address : $("#address").val(),
    				work_year : $("#work_year").val(),
    				xueli : $("#xueli").val(),
    				renshu : $("#renshu").val(),
    				cellphone : $("#cellphone").val(),
    				zhiwei : $("#zhiwei").val(),
    				consumer_id : $("#consumer_id").val(),
    		}
            var qUrl="/ssm/job/save.do";
            $.post(qUrl,postData,function(res){
             if(res.code=="01"){
                 layer.closeAll();
                 layer.msg("保存成功");
             }else{
                 layer.msg("保存失败");
             }
         });
            return false;
    });

    
});